﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<style>
    .layui-form-label {
        width: 160px
    }

    .layui-input-block {
        margin-left: 200px;
    }

    .layui-form-item {
        margin-bottom: 30px; /* 每个行之间的距离 */
        width: 480px
    }

</style>
<form class="layui-form" action="">
    <table>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建人名称</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="Id" name="Id" style="display:none">
                        <input type="text" id="CreateName" name="CreateName" lay-verify="required" placeholder="请输入创建人名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="CreateDate" name="CreateDate" id="ID-laydate-demo" placeholder="yyyy-MM-dd" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">到货通知单</label>
                    <div class="layui-input-block">
                        <input type="text" id="ArrivalNotice" name="ArrivalNotice" lay-verify="required" placeholder="请输入到货通知单" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">客户订单号</label>
                    <div class="layui-input-block">
                        <input type="text" id="CustomerOrderNumber" name="CustomerOrderNumber" lay-verify="required" placeholder="请输入客户订单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" id="Remarks" name="Remarks" lay-verify="required" placeholder="备注" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="ProductCode" name="ProductCode" lay-verify="required" placeholder="请输入商品编码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="ProductName" name="ProductName" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">预约数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="ScheduledQuantity" name="ScheduledQuantity" lay-verify="required" placeholder="请输入预约数量" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>

        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">已登记数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="RegisteredQuantity" name="RegisteredQuantity" lay-verify="required" placeholder="请输入已登记数量" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">未收货数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="UnreceivedQuantity" name="UnreceivedQuantity" lay-verify="required" placeholder="请输入未收货数量" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>

        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">生产日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="ProductionDate" name="ProductionDate" id="ID-laydate-demo" placeholder="yyyy-MM-dd" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">批次</label>
                    <div class="layui-input-block">
                        <input type="text" id="BatchNumber" name="BatchNumber" lay-verify="required" placeholder="请输入批次" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>

        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">储位</label>
                    <div class="layui-input-block">
                        <input type="text" id="StorageLocation" name="StorageLocation" lay-verify="required" placeholder="请输入储位" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">托盘</label>
                    <div class="layui-input-block">
                        <input type="text" id="PalletNumber" name="PalletNumber" lay-verify="required" placeholder="请输入托盘" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>

        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位</label>
                    <div class="layui-input-block">
                        <input type="text" id="Unit" name="Unit" lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        <button type="button" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>

<script>

    $(function () {
        getInfo()
    })

    function getInfo() {
        $.ajax({
            url: "/BatchReceiving/GetBatchReceivingInfo",
            data: { id: @ViewBag.id},
            type: "get",
            datatype: "json",
            success: function (res) {
                var id = res.data.id
                console.log(res.data)
                $("#Id").val(res.data.id);
                $("#CreateName").val(res.data.createName)
                $("#CreateDate").val(res.data.createDate.substring(0,10))
                $("#ArrivalNotice").val(res.data.arrivalNotice)
                $("#CustomerOrderNumber").val(res.data.customerOrderNumber)
                $("#Remarks").val(res.data.remarks)
                $("#ProductCode").val(res.data.productCode)
                $("#ProductName").val(res.data.productName)
                $("#ScheduledQuantity").val(res.data.scheduledQuantity)
                $("#RegisteredQuantity").val(res.data.registeredQuantity)
                $("#UnreceivedQuantity").val(res.data.unreceivedQuantity)
                $("#ProductionDate").val(res.data.productionDate.substring(0,10))
                $("#BatchNumber").val(res.data.batchNumber)
                $("#StorageLocation").val(res.data.storageLocation)
                $("#PalletNumber").val(res.data.palletNumber)
                $("#Unit").val(res.data.unit)
            }
        })
    }

    //关闭弹框
    function closeWorkstation() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        form.on('submit(add)', function (data) {
            var field = data.field;
            console.log(field);
            $.ajax({
                url: '/BatchReceiving/UpdateBatchReceiving',
                type: 'POST',
                data: field,
                dataType: 'json',
                success: function (res) {
                    if (res > 0) {
                        layer.alert('修改成功', { title: '操作结果' }, function () {
                            layer.closeAll();
                            closeWorkstation()
                        });
                    }
                    else{
                        layer.alert('修改失败：' + res.msg, { title: '操作结果' });
                    }
                },
                error: function (err) {
                    // 处理添加失败的情况
                    layer.alert('修改失败：网络异常，请稍后重试', { title: '操作结果' });
                    console.error('修改失败', err);
                }
            });

            return false; // 阻止默认 form 提交
        });
    });
</script>

